﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Tasks.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class Log
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteLog(Exception ex)
        {
            WriteLog(ex, "");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteLog(string msg)
        {
            WriteLog(null, msg);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteLog(Exception ex, string otherMsg)
        {
            string str = "";
            try
            {
                str += string.Format(@"
DateTime:{0}", DateTime.Now.ToString());

                if (ex != null)
                {
                    str += string.Format(@"
Message:{0}
StackTrace:
{1}
Source:{2}
"
                         , ex.Message
                         , ex.StackTrace
                         , ex.Source

                    );
                }
                str += string.Format(@"
ExtMessage:{0}", otherMsg);
           
                string filePath = AppDomain.CurrentDomain.BaseDirectory + "log\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

                StreamWriter sw = new StreamWriter(filePath, true);
                sw.WriteLine(str);
                sw.Close();
            }
            catch (Exception ex1)
            {

            }
        }
    }
}
